from data_structure import ListNode
from utils import util
class Solution:
    # @param head, a ListNode
    # @return a boolean
    def isPalindrome(self, head):
        # Write your code here
        valList = []
        point = head
        isOk = True
        while point != None:
            valList.append(point.val)
            point = point.next
        
        listLen = len(valList)
        if listLen > 0:
            mid = (listLen+1)/2
            leftValList = valList[:mid]
            rightValList = valList[-mid:]
            rightValList.reverse()
            isOk = (leftValList == rightValList)
            
        return isOk


def testCase(list,expect):
    solution = Solution()
    head = util.listToListNode(list, ListNode)
    #util.printListNode(head)
    isOk = solution.isPalindrome(head)
    assert isOk==expect, expect

if __name__=='__main__':
    testCase([1],True)
    testCase([1,2,1],True)
    testCase([3,4,4,3],True)

    testCase([1,2],False)
    testCase([3,4,4,5],False)
    


